<?php

namespace App\Models;

class Image extends BaseModel
{
    // 批量插入数据的时候，需要设置。否则 报错 fillable 或 Field 'local_url' doesn't have a default value
    protected $fillable = [
        'title', 'path'
    ];

    const FOR_VIDEO = 0;


    public static $forMap = [
        self::FOR_VIDEO => '短视频',
    ];

    public function imaged(){
        return $this->morphTo(null,'used_for','used_id');
    }

    public function addFromVideo(Video $video, $imgPath){
        $this->title = $video->title;
        $this->used_id = $video->id;
        $this->path = $imgPath;
        $this->save();
        return $this;
    }
}
